package cate.game.role.res.holy_pet.core;

import easy.java.dev.note.NoteField;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 灵宠站位
 *
 * @author ShenSL
 * @since 2023/8/28 10:20
 */
@Data
public class HolyPetPosition {
    @NoteField("灵宠站位")
    private Map<Integer, Integer> petPos;

    /**
     * 初始化
     *
     * @param max 最大位置
     */
    public void initialize(int max) {
        if (petPos == null) {
            petPos = new HashMap<>();
        }
        petPos.entrySet().removeIf(e -> e.getKey() > max);
        for (int i = 1; i <= max; i++) {
            if (!petPos.containsKey(i)) {
                petPos.put(i, 0);
            }
        }
    }

    /**
     * 拷贝方案
     */
    public void readFromPosition(HolyPetPosition position) {
        Map<Integer, Integer> newPos = new HashMap<>();
        petPos.forEach((k, v) -> {
            if (position.getPetPos().containsKey(k)) {
                newPos.put(k, position.getPetPos().get(k));
            } else {
                petPos.put(k, 0);
            }
        });
        petPos = newPos;
    }
}
